from add_axis import *
from pic2char import *
from pic2gif import *
from pic2video import *
from video2pic import *


class Main():
    def __init__(self, videopath):
        """
        Main by CaiShu 2020.04.23
        用于转换视频 或 动图 为 字符串 视频 或 动图
        """
        self.videopath = videopath
        self.pro_frames_dir = f"{videopath.split('.')[0]}_pro_frames"   # 原型帧默认文件夹
        self.char_frames_dir = f"{videopath.split('.')[0]}_char_frames" # 字符画默认文件夹
        self.axis_frames_dir = f"{videopath.split('.')[0]}_axis_frames" # 添加了坐标轴的字符画默认文件夹

    def video2pic(self):
        video2pic0(self.pro_frames_dir, self.videopath)

    def pic2char(self, picsize=1, clarity=0.1, fontsize=10, skip=1, model="L"):
        pic2char0(self.char_frames_dir, self.pro_frames_dir, picsize, clarity, fontsize, skip, model)

    def add_axis(self, dpi,frames_dir = ''):
        if frames_dir == '':
            frames_dir = self.char_frames_dir
        add_axis0(self.axis_frames_dir, frames_dir, dpi)

    def pic2video(self, newvideopath, frames_dir, fps):
        pic2video0(newvideopath, frames_dir, fps)

    def pic2gif(self, gifpath, frames_dir, fps):
        pic2gif0(gifpath, frames_dir, fps)


if __name__ == "__main__":
    v = Main(r"fumo/fumo.gif")
    v.video2pic()
    v.pic2char(picsize=0.5, clarity=0.5, fontsize=2, skip=1, model="RGB")
    v.pic2video("fumo/fumo.avi", v.char_frames_dir, fps=10)

    v.add_axis(dpi=50)
    v.pic2video("fumo/fumo_axis.avi", v.axis_frames_dir, fps=10)

    v.pic2gif("fumo/fumo_char.gif", v.char_frames_dir, fps=10)
    v.pic2gif("fumo/fumo_axis.gif", v.axis_frames_dir, fps=10)
